<template>
	<div class="container">
		<tabBar currentPage="/pages/index/advisoryList"></tabBar>
		<navigationBar title="消息" mode="none"></navigationBar>
		<div class="content" :style="'padding-top: ' + (navigationBarHeight-1) + 'px;'">
			<!-- 		<div class="title-top" @click="read()">
				一键已读
			</div> -->
			<div class="nav-block">
				<div class="nav-item" @click="toNotificationLike()">
					<image src="/static/icons/chat1.png" mode=""></image>
					<span>赞和收藏</span>
				</div>
				<div class="nav-item" @click="toNotificationFollow()">
					<image src="/static/icons/chat2.png" mode=""></image>
					<span>新增关注</span>
				</div>
				<div class="nav-item" @click="toNotificationComment()">
					<image src="/static/icons/chat3.png" mode=""></image>
					<span>评论和@</span>
				</div>
			</div>
			<div class="list">
				<div class="item" @click="toSystemMsg">
					<div class="avatar">
						<image src="../../static/icon/icon_xiaoxi_xitong.png" mode="aspectFill"></image>
					</div>
					<div class="info">
						<div class="title">
							<div class="nickname">系统消息</div>
							<div class="time">
								{{ userInfo.lastUnreadTime? $utils.timestampFormat(Date.parse( userInfo.lastUnreadTime)/1000) : ''}}
							</div>
						</div>
						<div class="desc">{{userInfo.lastUnreadSystemMessage || '暂无最新消息'}}
							<uni-badge v-if="userInfo.unreadSystemCount > 0" class="unread" :inverted="true"
								:text="userInfo.unreadSystemCount"
								:customStyle="{background: 'linear-gradient(180deg, #ED6D0C 0%, #F98922 100%)'}"></uni-badge>
						</div>
					</div>
				</div>
				<template v-for="(item, key) in list">
					<slide-left @delItem="(e)=>delChat(e,index)" :data_transit="item">
						<div class="item" @click="toAdvisory(item)">
							<div class="avatar">
								<image :src="item.avatar" mode="aspectFill"></image>
							</div>
							<div class="info">
								<div class="title">
									<div class="nickname">{{item.nickname || item.userName}}</div>
									<div class="time">
										{{ item.createTime? $utils.timestampFormat(Date.parse( item.createTime)/1000) :''}}
									</div>
								</div>
								<div class="desc">
									{{item.type == 1? item.content:item.type == 2? '【图片】':item.type == 3? '【商品、好物消息】':'【红包】' }}
									<uni-badge v-if="item.unreadCount > 0" class="unread" :inverted="true"
										:text="item.unreadCount"
										:customStyle="{background: 'linear-gradient(180deg, #ED6D0C 0%, #F98922 100%)'}"></uni-badge>
								</div>
							</div>
						</div>
					</slide-left>
				</template>

			</div>
		</div>
		<div class="empty" v-show="false">
			<image class="empty-img" src="../../static/icon/icon_wuxinxi.png" mode=""></image>
			<div class="title">暂无信息</div>
		</div>
		<!-- 添加	订阅 -->
		<!-- <uni-popup ref="subscribeMsg" type="center" :maskClick="true">
			<div class="setPrice">
				<div class="price-title">订阅信息</div>
				<div class="bottom">
					<span class="cannel" @click="subscribeMessages()">取消</span>
					<span class="yes on" @click="subscribeMessages()">确定</span>
				</div>
			</div>
		</uni-popup> -->
	</div>
</template>

<script>
	import data from '@/js/index/advisoryList/data.js';
	import methods from '@/js/index/advisoryList/methods.js';
	import {
		mapState
	} from 'vuex';
	import navigationBar from '../../components/navigationBar.vue';
	import slideLeft from '../../components/slideLeft/slideLeft.vue';
	import uniPopup from "@/components/uni-popup/uni-popup.vue";
	import uniBadge from '@/components/uni-badge.vue';
	export default {
		data,
		methods,
		onLoad() {

			// this.showSubscribeMsg()

		},
		onPullDownRefresh() {
			this.getPageList()
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onShow() {
			this.getUserInfo()
			this.getPageList()
			this.changeTime()
			// //连接
			this.connect()
			this.connectlisenter()
		},
		onHide() {
			clearInterval(this.timeRequest)
			console.log("onHide 清除")
			// this.unsubscribe()
		},
		onUnload() {
			clearInterval(this.timeRequest)
			console.log("onUnload 清除")
			// this.unsubscribe()
		},
		components: {
			navigationBar,
			slideLeft,
			uniPopup,
			uniBadge
		},
		computed: {
			...mapState(['navigationBarHeight', 'userInfo'])
		},
		filters: {
			fmtContent(value) {
				value = JSON.parse(value)
				if (value.message_type === 'image') {
					return '[图片消息]'
				} else {
					return value.content
				}
			}
		}
	};
</script>
<style>
	page {
		background: #FFF;
	}

	uni-page {
		background: #FFF;
	}
</style>
<style scoped lang="scss">
	@import '~@/style/index/advisoryList.scss';
</style>